//
//  Tweet.m
//  Coding_iOS
//
//  Created by Ease on 15/3/9.
//  Copyright (c) 2015年 Coding. All rights reserved.
//

#import "Tweet.h"

#define kDevice_Is_iPhone5 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 1136), [[UIScreen mainScreen] currentMode].size) : NO)
#define kDevice_Is_iPhone6 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(750, 1334), [[UIScreen mainScreen] currentMode].size) : NO)
#define kDevice_Is_iPhone6Plus ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1242, 2208), [[UIScreen mainScreen] currentMode].size) : NO)


static Tweet *_tweetForSend = nil;

@implementation Tweet
- (instancetype)init
{
    self = [super init];
    if (self) {
 
    }
    return self;
}

+(Tweet *)tweetForSend{
    if (!_tweetForSend) {
        _tweetForSend = [[Tweet alloc] init];
    }
    return _tweetForSend;
}

#pragma mark ALAsset
 - (void)addASelectedAssetURL:(NSURL *)assetURL{
    if (!_selectedAssetURLs) {
        _selectedAssetURLs = [NSMutableArray new];
    }
    if (!_tweetImages) {
        _tweetImages = [NSMutableArray new];
    }
    
    [_selectedAssetURLs addObject:assetURL];
}

 
//- (void)deleteATweetImage:(TweetImage *)tweetImage{
//    NSMutableArray *tweetImages = [self mutableArrayValueForKey:@"tweetImages"];//为了kvo
//    [tweetImages removeObject:tweetImage];
//    if (tweetImage.assetURL) {
//        [self.selectedAssetURLs removeObject:tweetImage.assetURL];
//    }
//}

@end

@implementation TweetImage
//+ (instancetype)tweetImageWithAssetURL:(NSURL *)assetURL{
//    TweetImage *tweetImg = [[TweetImage alloc] init];
//    tweetImg.uploadState = TweetImageUploadStateInit;
//    tweetImg.assetURL = assetURL;
//    
//    void (^selectAsset)(ALAsset *) = ^(ALAsset *asset){
//        if (asset) {
//            UIImage *highQualityImage = [UIImage fullScreenImageALAsset:asset];
//            UIImage *thumbnailImage = [UIImage imageWithCGImage:[asset thumbnail]];
//            dispatch_async(dispatch_get_main_queue(), ^{
//                tweetImg.image = highQualityImage;
//                tweetImg.thumbnailImage = thumbnailImage;
//            });
//        }
//    };
//    
//    ALAssetsLibrary *assetsLibrary = [[ALAssetsLibrary alloc] init];
//    @weakify(assetsLibrary);
//    [assetsLibrary assetForURL:assetURL resultBlock:^(ALAsset *asset) {
//        if (asset) {
//            selectAsset(asset);
//        }else{
//            @strongify(assetsLibrary);
//            [assetsLibrary enumerateGroupsWithTypes:ALAssetsGroupPhotoStream usingBlock:^(ALAssetsGroup *group, BOOL *stop) {
//                [group enumerateAssetsUsingBlock:^(ALAsset *result, NSUInteger index, BOOL *stopG) {
//                    if([result.defaultRepresentation.url isEqual:assetURL]) {
//                        selectAsset(result);
//                        *stop = YES;
//                        *stopG = YES;
//                    }
//                }];
//            } failureBlock:^(NSError *error) {
//                [NSObject showHudTipStr:@"读取图片失败"];
//            }];
//        }
//    }failureBlock:^(NSError *error) {
//        [NSObject showHudTipStr:@"读取图片失败"];
//    }];
//    return tweetImg;
//
//}
//
//+ (instancetype)tweetImageWithAssetURL:(NSURL *)assetURL andImage:(UIImage *)image{
//    TweetImage *tweetImg = [[TweetImage alloc] init];
//    tweetImg.uploadState = TweetImageUploadStateInit;
//    tweetImg.assetURL = assetURL;
//    tweetImg.image = image;
//    //tweetImg.thumbnailImage = [image scaledToSize:CGSizeMake(kScaleFrom_iPhone5_Desgin(70), kScaleFrom_iPhone5_Desgin(70)) highQuality:YES];
//    return tweetImg;
//}

@end